home *** CD-ROM | disk | FTP | other *** search
/ Aminet 23 / Aminet 23 (1998)(GTI - Schatztruhe)[!][Feb 1998].iso / Aminet / misc / emu / amiSPIMsrc.lha / lib / trap.handler
Text File  |  1994-02-03  |  3KB  |  104 lines

  1. # SPIM S20 MIPS simulator.
  2. # The default trap handler for spim.
  3. # Copyright (C) 1990-1992 James Larus, larus@cs.wisc.edu.
  4. # ALL RIGHTS RESERVED.
  5. #
  6. # SPIM is distributed under the following conditions:
  7. #
  8. # You may make copies of SPIM for your own use and modify those copies.
  9. #
  10. # All copies of SPIM must retain my name and copyright notice.
  11. #
  12. # You may not sell SPIM or distributed SPIM in conjunction with a commerical
  13. # product or service without the expressed written consent of James Larus.
  14. #
  15. # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16. # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18. # PURPOSE.
  19. #
  20.  
  21. # $Header: /home/primost/larus/Software/SPIM/RCS/trap.handler,v 1.19 1993/01/15 22:21:40 larus Exp $
  22.  
  23.  
  24. # Define the exception handling code.  This must go first!
  25.  
  26.     .kdata
  27. __m1_:    .asciiz "  Exception "
  28. __m2_:    .asciiz " occurred and ignored\n"
  29. __e0_:    .asciiz "  [Interrupt] "
  30. __e1_:    .asciiz    ""
  31. __e2_:    .asciiz    ""
  32. __e3_:    .asciiz    ""
  33. __e4_:    .asciiz    "  [Unaligned address in inst/data fetch] "
  34. __e5_:    .asciiz    "  [Unaligned address in store] "
  35. __e6_:    .asciiz    "  [Bad address in text read] "
  36. __e7_:    .asciiz    "  [Bad address in data/stack read] "
  37. __e8_:    .asciiz    "  [Error in syscall] "
  38. __e9_:    .asciiz    "  [Breakpoint] "
  39. __e10_:    .asciiz    "  [Reserved instruction] "
  40. __e11_:    .asciiz    ""
  41. __e12_:    .asciiz    "  [Arithmetic overflow] "
  42. __e13_:    .asciiz    "  [Inexact floating point result] "
  43. __e14_:    .asciiz    "  [Invalid floating point result] "
  44. __e15_:    .asciiz    "  [Divide by 0] "
  45. __e16_:    .asciiz    "  [Floating point overflow] "
  46. __e17_:    .asciiz    "  [Floating point underflow] "
  47. __excp:    .word __e0_,__e1_,__e2_,__e3_,__e4_,__e5_,__e6_,__e7_,__e8_,__e9_
  48.     .word __e10_,__e11_,__e12_,__e13_,__e14_,__e15_,__e16_,__e17_
  49. s1:    .word 0
  50. s2:    .word 0
  51.  
  52.     .ktext 0x80000080
  53.     .set noat
  54.     # Because we are running in the kernel, we can use $k0/$k1 without
  55.     # saving their old values.
  56.     move $at $k1    # Save $at
  57.     .set at
  58.     sw $v0 s1    # Not re-entrent and we can't trust $sp
  59.     sw $a0 s2
  60.     mfc0 $k0 $13    # Cause
  61.         sgt $v0 $k0 0x44 # ignore interrupt exceptions
  62.         bgtz $v0 ret
  63.         addu $0 $0 0
  64.     li $v0 4    # syscall 4 (print_str)
  65.     la $a0 __m1_
  66.     syscall
  67.     li $v0 1    # syscall 1 (print_int)
  68.         srl $a0 $k0 2    # shift Cause reg
  69.     syscall
  70.     li $v0 4    # syscall 4 (print_str)
  71.     lw $a0 __excp($k0)
  72.     syscall
  73.     beq $k0 24 bad_pc
  74.     li $v0 4    # syscall 4 (print_str)
  75.     la $a0 __m2_
  76.     syscall
  77.     mtc0 $0, $13    # Clear Cause register
  78. ret:    lw $v0 s1
  79.     lw $a0 s2
  80.     mfc0 $k0 $14    # EPC
  81.     .set noat
  82.     move $k1 $at    # Restore $at
  83.     .set at
  84.     rfe        # Return from exception handler
  85.     addiu $k0 $k0 4 # Return to next instruction
  86.     jr $k0
  87. bad_pc:    li $v0 10    # Exit upon bad PC
  88.     syscall        # syscall 10 (exit)
  89.  
  90.  
  91. # Standard startup code.  Invoke the routine main with no arguments.
  92.  
  93.     .text
  94.     .globl __start
  95. __start: 
  96.     lw $a0, 0($sp)    # argc
  97.     addiu $a1, $sp, 4 # argv
  98.     addiu $a2, $a1, 4 # envp
  99.     sll $v0, $a0, 2
  100.     addu $a2, $a2, $v0
  101.     jal main
  102.     li $v0 10
  103.     syscall        # syscall 10 (exit)
  104.